<?php

  //
  // Memorii Web
  // content/word.php
  //
  // Layout for a word
  //
  
  if(file_exists('../../script/db/db.php'))
	  require_once('../../script/db/db.php');
	elseif(file_exists('../script/db/db.php'))
	  require_once('../script/db/db.php');
	else
  	require_once('script/db/db.php');	
  
  if(session_id()=='')
  	session_start();
  
  $word_id = '0';
  if( isset($_POST['word_id']) && $_POST['word_id']!='' ) {
    $word_id = $_POST['word_id'];
  }
  elseif( isset($_SESSION['current_word_id'])) {
  	$word_id = $_SESSION['current_word_id'];
  }
  $_SESSION['current_word_id'] = $word_id;
  
  $db_connection = db_connect();
  
  $word_data = db_get_word($db_connection, $word_id);
  
?>
<div class="word_bloc">
	<div class="lateral_bloc_actions">
		<div class="parent_folder_link" onclick="go_folder('<?php $word_data['parent_folder_id'] ?>');">
			<span class="content_icon"><img src="img/folder/folder_50.png" alt="folder" /></span>
      <span>↑</span>
    </div>
    <div>
    	<button onclick="delete_word('<?php echo $word_data['word_id']; ?>');">Delete</button>
    </div>
	</div>
	<div class="word_bloc_content">
		<div class="word"><span class="editable" onclick="edit_word('<?php echo $word_data['word_id']; ?>');"><?php if($word_data['word']=='') { echo '<span class="default">字</span>';} else { echo $word_data['word']; } ?></span></div>
		<div class="reading"><span class="editable" onclick="edit_word_reading('<?php echo $word_data['word_id']; ?>');"><?php if($word_data['reading']=='') { echo '<span class="default">Reading</span>';} else { echo $word_data['reading']; } ?></span></div>
		<div class="meaning"><span class="editable" onclick="edit_word_meaning('<?php echo $word_data['word_id']; ?>');"><?php if($word_data['meaning']=='') { echo '<span class="default">Meaning</span>';} else { echo $word_data['meaning']; } ?></span></div>
	</div>
</div>
<?php
	db_disconnect($db_connection);
?>